package com.leiyuee.designpattern.strategy.controller;

import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.leiyuee.designpattern.strategy.params.PayParam;
import com.leiyuee.designpattern.strategy.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author : Yu_Lei
 * @create 2024/5/8
 */


@Slf4j
@RestController
public class PayController {

    @Resource
    private PayService payService;

    @PostMapping("/pay")
    public String pay(@RequestBody PayParam param) {
        log.info("PayController pay param:{}", JSON.toJSONString(param));
        payService.setPayStrategy(SpringUtil.getBean(param.getPayType()));

        return payService.pay(param.getAmount());
    }


}
